home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Compendium Deluxe 2
/
LSD and 17bit Compendium Deluxe - Volume II.iso
/
a
/
prog
/
asmsrc
/
thesource-7.lha
/
Source
/
PushBClass.lha
/
pushbclass
/
pushbclass.c
next >
Wrap
C/C++ Source or Header
|
1994-06-11
|
6KB
|
222 lines
/*
* PushButtonClass
*/
#include <string.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/nodes.h>
#include <exec/ports.h>
#include <intuition/intuition.h>
#include <intuition/classes.h>
#include <intuition/classusr.h>
#include <intuition/gadgetclass.h>
#include <intuition/imageclass.h>
#include <graphics/gfxbase.h>
#include <graphics/text.h>
#include <utility/tagitem.h>
#include <utility/hooks.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/graphics_protos.h>
#include <clib/utility_protos.h>
#include <clib/alib_protos.h>
#include <clib/alib_stdio_protos.h>
#include "Gadget.h"
#include "PushBClass.h"
extern struct GfxBase *GfxBase;
/*
* Local prototypes
*/
static BOOL SetPBIText(struct PushBData *, struct TagItem *);
static ULONG PushBDispatch(Class *, Object *, Msg);
/*
* External variables
*/
extern Class *PBClass;
/*
* Local variables
*/
static struct TagItem tmpTag[] = {
{GA_IntuiText, NULL},
{GA_Image, NULL},
{TAG_MORE, NULL}
};
static struct PushBTA pbTA;
/*
* SetPBIText
*/
static BOOL SetPBIText(struct PushBData *instData, struct TagItem *tagItems)
{
register char *text;
register BYTE upos;
if (text = (char *)GetTagData(PUSHB_Text, 0L, tagItems)) {
/* Setup first intuitext (button text) */
instData->PBIText1.FrontPen = instData->PBIText2.FrontPen
= instData->PBDrawInfo->dri_Pens[DETAILPEN];
instData->PBIText1.DrawMode = instData->PBIText2.DrawMode
= JAM1;
instData->PBIText1.IText = text;
/* Setup underlined key intuitext */
instData->PBIText1.NextText = NULL;
} else {
text = instData->PBIText1.IText;
}
if (text) {
if ((upos = (BYTE)GetTagData(PUSHB_UPos, 0L, tagItems))
&& upos > 0 && upos <= strlen(text)) {
/* Get character and length */
instData->PBIText2.IText = &instData->PBKey[0];
instData->PBIText2.IText[0] = text[upos-1];
text[upos-1] = 0;
instData->PBIText2.LeftEdge = IntuiTextLength(&instData->PBIText1);
text[upos-1] = instData->PBIText2.IText[0];
instData->PBIText1.NextText = &instData->PBIText2;
}
return TRUE;
}
return FALSE;
}
/*
* PushBDispatch
*/
static ULONG PushBDispatch(Class *class, Object *object, Msg msg)
{
register ULONG result = 0;
register struct PushBInst *instData;
register struct PushBData *pbData;
struct Gadget *gadg;
struct Image *img;
switch (msg->MethodID) {
case OM_NEW:
if (img = NewObject(NULL, "frameiclass", IA_FrameType, FRAME_BUTTON, TAG_END)) {
if (pbData = AllocMem(sizeof(struct PushBData), MEMF_CLEAR)) {
pbData->PBDrawInfo = (struct DrawInfo *)GetTagData(GA_DrawInfo, 0L, ((struct opSet *)msg)->ops_AttrList);
pbData->PBIText1.ITextFont = &pbTA.PBTextAttr1;
pbData->PBIText2.ITextFont = &pbTA.PBTextAttr2;
if (SetPBIText(pbData, ((struct opSet *)msg)->ops_AttrList)) {
tmpTag[0].ti_Data = (ULONG)(&pbData->PBIText1);
tmpTag[1].ti_Data = (ULONG)img;
tmpTag[2].ti_Data = (ULONG)((struct opSet *)msg)->ops_AttrList;
((struct opSet *)msg)->ops_AttrList = tmpTag;
if (result = (ULONG)(gadg = (struct Gadget *)DoSuperMethodA(class, object, msg))) {
((struct opSet *)msg)->ops_AttrList = (struct TagItem *)tmpTag[1].ti_Data;
instData = INST_DATA(class, gadg);
instData->PBData = pbData;
break;
}
((struct opSet *)msg)->ops_AttrList = (struct TagItem *)tmpTag[1].ti_Data;
}
FreeMem(pbData, sizeof(struct PushBData));
}
DisposeObject(img);
result = 0;
}
break;
case OM_SET:
instData = INST_DATA(class, object);
if (SetPBIText(instData->PBData, ((struct opSet *)msg)->ops_AttrList)) {
result = SetSuperAttrs(class, object,
GA_IntuiText, &instData->PBData->PBIText1,
TAG_END);
}
result = DoSuperMethodA(class, object, msg);
break;
case OM_DISPOSE:
instData = INST_DATA(class, object);
FreeMem(instData->PBData, sizeof(struct PushBData));
DisposeObject(((struct Gadget *)object)->GadgetRender);
/* NOTE: I'm falling through here! */
default:
result = DoSuperMethodA(class, object, msg);
break;
}
return(result);
}
/*
* MakePushBClass
*/
Class *MakePushBClass(void)
{
Class *class = NULL;
extern ULONG HookEntry(); /* defined in amiga.lib */
if (class = MakeClass(NULL, "frbuttonclass", NULL,
sizeof(struct PushBInst), 0)) {
class->cl_Dispatcher.h_Entry = HookEntry;
class->cl_Dispatcher.h_SubEntry = PushBDispatch;
pbTA.PBTextAttr1.ta_Name = pbTA.PBTextAttr2.ta_Name
= GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
pbTA.PBTextAttr1.ta_YSize = pbTA.PBTextAttr2.ta_YSize
= GfxBase->DefaultFont->tf_YSizendow,
struct Requester *req,
struct DrawInfo *drawInfo,
struct Gadget *prevGadg,
WORD left, WORD top,
char *text, BYTE uposht, STDPBHEIGHT,
TAG_END);
}
return tmpGadget;
}
/*
* ChangePushButton
*/
void ChangePushButton(struct Gadget *gadget,
struct Window *window,
struct Requester *req,
char *text, BYTE upos)
{
SetGadgetAttrs(gadget, window, req, GA_Width, STDPBWIDTH, GA_Height, STDPBHEIGHT,
PUSHB_Text, text, PUSHB_UPos, upos,
TAG_END);
RefreshGList(gadget, window, req, 1);
}